//
//  CZD_DetailTiHuoCell.m
//  LogisticsSupplier
//
//  Created by 吕晶 on 2020/9/27.
//  Copyright © 2020 吕晶. All rights reserved.
//

#import "CZD_DetailTiHuoCell.h"

@interface CZD_DetailTiHuoCell ()

@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UILabel *noTitleLab;
@property (nonatomic, strong) UILabel *noLab;
@property (nonatomic, strong) UILabel *marginLine1;

@property (nonatomic, strong) UIImageView *tiImgView;
@property (nonatomic, strong) UIScrollView *faHuoAddressScrollView;
@property (nonatomic, strong) UILabel *marginLine2;
@property (nonatomic, strong) UIImageView *shouImgView;
@property (nonatomic, strong) UILabel *shouNameLab;
@property (nonatomic, strong) UILabel *shouPhoneLab;
@property (nonatomic, strong) UILabel *shouAddressLab;
@property (nonatomic, strong) UILabel *shouCompanyLab;
@property (nonatomic, strong) UILabel *marginLine3;
@property (nonatomic, strong) UILabel *linkLine;

@property (nonatomic, strong) UIButton *listBtn;

@end

@implementation CZD_DetailTiHuoCell

+ (instancetype)CZD_DetailTiHuoCellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"CZD_DetailTiHuoCell";
    CZD_DetailTiHuoCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (cell == nil) {
        cell = [[CZD_DetailTiHuoCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = Color_backgroundColor;
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.bgView = [UIView new];
        self.bgView.backgroundColor = HexColor(0xffffff);
        self.bgView.layer.masksToBounds = YES;
        self.bgView.layer.cornerRadius = 6;
        [self.contentView addSubview:self.bgView];
        
        self.noTitleLab = [UILabel new];
        self.noTitleLab.font = [UIFont systemFontOfSize:16];
        self.noTitleLab.textColor = HexColor(0x9C9DB3);
        [self.bgView addSubview:self.noTitleLab];
        
        self.noLab = [UILabel new];
        self.noLab.font = BoldFontOfSize(16);
        self.noLab.textColor = Color_ThemeColor;
        self.noLab.textAlignment = NSTextAlignmentRight;
        [self.bgView addSubview:self.noLab];
        
        self.marginLine1 = [UILabel new];
        self.marginLine1.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine1];
        
        self.tiImgView = [UIImageView new];
        self.tiImgView.image = [UIImage imageNamed:@"icon_add_ti"];
        [self.bgView addSubview:self.tiImgView];
        
        self.faHuoAddressScrollView = [UIScrollView new];
        [self.bgView addSubview:self.faHuoAddressScrollView];
        
        self.marginLine2 = [UILabel new];
        self.marginLine2.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine2];
        
        self.shouImgView = [UIImageView new];
        self.shouImgView.image = [UIImage imageNamed:@"icon_add_xie"];
        [self.bgView addSubview:self.shouImgView];
        
        self.shouNameLab = [UILabel new];
        self.shouNameLab.textColor = HexColor(0x2B2C44);
        self.shouNameLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.shouNameLab];
        
        self.shouPhoneLab = [UILabel new];
        self.shouPhoneLab.textColor = Color_ThemeColor;
        self.shouPhoneLab.font = BoldFontOfSize(16);
        [self.bgView addSubview:self.shouPhoneLab];
        
        self.shouAddressLab = [UILabel new];
        self.shouAddressLab.textColor = HexColor(0x9C9DB3);
        self.shouAddressLab.font = [UIFont systemFontOfSize:14];
        self.shouAddressLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouAddressLab];
        
        self.shouCompanyLab = [UILabel new];
        self.shouCompanyLab.textColor = HexColor(0x9C9DB3);
        self.shouCompanyLab.font = [UIFont systemFontOfSize:14];
        self.shouCompanyLab.numberOfLines = 0;
        [self.bgView addSubview:self.shouCompanyLab];
        
        self.marginLine3 = [UILabel new];
        self.marginLine3.backgroundColor = Color_backgroundColor;
        [self.bgView addSubview:self.marginLine3];
        
        self.linkLine = [UILabel new];
        self.linkLine.backgroundColor = HexColorA(0x3D68EB, 0.2);
        [self.bgView addSubview:self.linkLine];
        
        self.listBtn = [UIButton new];
        self.listBtn.backgroundColor = HexColorA(0x3D68EB, 0.1);
        self.listBtn.layer.masksToBounds = YES;
        self.listBtn.layer.cornerRadius = 6;
        [self.listBtn setTitle:@"我的提货清单" forState:0];
        [self.listBtn setTitleColor:Color_ThemeColor forState:0];
        self.listBtn.titleLabel.font = BoldFontOfSize(16);
        [self.listBtn addTarget:self action:@selector(listClick) forControlEvents:UIControlEventTouchUpInside];
        [self.bgView addSubview:self.listBtn];
    }
    return self;
}

- (void)listClick {
    if (self.goodListBlock) {
        self.goodListBlock();
    }
}

-(void)setModel:(CaoZuoDanDiaoDuModel *)model {
    _model = model;
    [self configUI];
}

- (void)configUI {
    self.bgView.nim_left = 15;
    self.bgView.nim_top = 10;
    self.bgView.nim_width = ScreenW - 30;
    
    self.noTitleLab.text = @"提货单号：";
    self.noTitleLab.nim_left = 15;
    self.noTitleLab.nim_top = 15;
    [self.noTitleLab sizeToFit];
    
    self.noLab.text = self.model.dp_num;
    [self.noLab sizeToFit];
    self.noLab.nim_left = self.bgView.nim_width - 15 - self.noLab.nim_width;
    self.noLab.nim_centerY = self.noTitleLab.nim_centerY;
    
    self.marginLine1.frame = CGRectMake(0, self.noTitleLab.nim_bottom + 15, self.bgView.nim_width, 2);
    
    self.faHuoAddressScrollView.frame = CGRectMake(59, 15 + self.marginLine1.nim_bottom, self.bgView.nim_width - 59, 67);
    CGFloat scrConW = self.bgView.nim_width - 71 - 59;
    self.faHuoAddressScrollView.contentSize = CGSizeMake(scrConW * 1, 67);
    [self.faHuoAddressScrollView.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
//    __block CGFloat scrConLeft = 0;
//    [self.model.origin enumerateObjectsUsingBlock:^(CaoZuoDanDiaoDuAddressModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, scrConW, 67)];
//        scrConLeft = view.nim_right;
        
        UILabel *tiNameLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 2.5, scrConW - 10, 17)];
        tiNameLab.textColor = HexColor(0x2B2C44);
        tiNameLab.font = BoldFontOfSize(16);
    tiNameLab.text = [NSString stringWithFormat:@"%@ %@",self.model.origin.contract_name,self.model.origin.contract_tel];
        [view addSubview:tiNameLab];
        
        UILabel *tiAddressLab = [[UILabel alloc] initWithFrame:CGRectMake(0, tiNameLab.nim_bottom + 10, tiNameLab.nim_width, 15)];
        tiAddressLab.textColor = HexColor(0x9C9DB3);
        tiAddressLab.font = [UIFont systemFontOfSize:14];
    tiAddressLab.text = self.model.origin.info;
        [view addSubview:tiAddressLab];
        
        UILabel * tiCompanyLab = [[UILabel alloc] initWithFrame:CGRectMake(0, tiAddressLab.nim_bottom + 5, tiAddressLab.nim_width, 15)];
        tiCompanyLab.textColor = HexColor(0x9C9DB3);
        tiCompanyLab.font = [UIFont systemFontOfSize:14];
    tiCompanyLab.text = self.model.origin.name;
        [view addSubview:tiCompanyLab];
        
        [self.faHuoAddressScrollView addSubview:view];
//    }];
    
    self.marginLine2.frame = CGRectMake(52, 92 + self.marginLine1.nim_bottom, self.bgView.nim_width - 52, 1);

    self.shouNameLab.text = [NSString stringWithFormat:@"%@ %@",self.model.destination.contract_name,self.model.destination.contract_tel];
    [self.shouNameLab sizeToFit];
    self.shouNameLab.nim_left = 59;
    self.shouNameLab.nim_top = 10 + self.marginLine2.nim_bottom;
    self.shouNameLab.nim_width = self.bgView.nim_width - 70 - 10 - self.shouNameLab.nim_left;
    
    self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
    self.shouAddressLab.text = self.model.destination.info;
    self.shouAddressLab.nim_left = self.shouNameLab.nim_left;
    self.shouAddressLab.nim_top = self.shouNameLab.nim_bottom + 10;
    [self.shouAddressLab sizeToFit];
    self.shouAddressLab.nim_width = self.shouNameLab.nim_width;
    
    self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
    self.shouCompanyLab.text = self.model.destination.name;
    self.shouCompanyLab.nim_left = self.shouAddressLab.nim_left;
    self.shouCompanyLab.nim_top = self.shouAddressLab.nim_bottom + 5;
    [self.shouCompanyLab sizeToFit];
    self.shouCompanyLab.nim_width = self.shouAddressLab.nim_width;
    
    self.marginLine3.nim_left = 0;
    self.marginLine3.nim_top = self.shouCompanyLab.nim_bottom + 15;
    self.marginLine3.nim_width = self.bgView.nim_width;
    self.marginLine3.nim_height = 2;
    
    self.tiImgView.nim_width = 22;
    self.tiImgView.nim_height = 22;
    self.tiImgView.nim_left = 20;
    self.tiImgView.nim_top = (self.marginLine2.nim_top - self.marginLine1.nim_bottom - self.tiImgView.nim_width) * 0.5 + self.marginLine1.nim_bottom;
    
    self.shouImgView.nim_width = 22;
    self.shouImgView.nim_height = 22;
    self.shouImgView.nim_left = 20;
    self.shouImgView.nim_top = (self.marginLine3.nim_top - self.marginLine2.nim_bottom - self.shouImgView.nim_height) * 0.5 + self.marginLine2.nim_bottom;
    
    self.linkLine.nim_width = 2;
    self.linkLine.nim_top = self.tiImgView.nim_bottom + 3;
    self.linkLine.nim_height = self.shouImgView.nim_top - 3 - self.linkLine.nim_top;
    self.linkLine.nim_centerX = self.tiImgView.nim_centerX;
    
    self.listBtn.frame = CGRectMake(15, self.marginLine3.nim_bottom + 10, self.bgView.nim_width - 30, 44);
    
    self.bgView.nim_height = self.listBtn.nim_bottom + 10;
    
    self.height = self.bgView.nim_bottom;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
